 
var pageIndex = 0;     //页面索引初始值  
var pageSize = 15;     //每页显示条数初始化，修改显示条数，修改这里即可
var querypageIndex = 0;     //页面索引初始值  
var querypageSize = 10;
$(function(){
	$("#Pagination").pagination(getCount(), {  
        callback: PageCallback,  
        prev_text: '上一页',       //上一页按钮里text  
        next_text: '下一页',       //下一页按钮里text  
        items_per_page: pageSize,  //显示条数  
        num_display_entries: 5,    //连续分页主体部分分页条目数  
        current_page: pageIndex,   //当前页索引  
        num_edge_entries: 5        //两侧首尾分页条目数  
    });    

    //翻页调用  
    function PageCallback(index, jq) { 
    	headTable();
        InitTable(index);  
    }  
    
    function getCount(){
    	var count = "";
    	$.ajax({
        	type : 'get',
			dataType: 'text',
			contentType: "application/json",
			async: false, 
            url: ctx + "/au.do?action=9",      //提交到一般处理程序请求数据  
            success: function(data) { 
            	count = data;
            	if(count == 0){
            		$("#Pagination").hide();
            	}else{
            		$("#Pagination").show();
            	}
            }  
         });  
    	
    	return count;
    }
});
//请求数据  
function InitTable(pageIndex) { 
    $.ajax({
    	type : 'get',
		dataType: 'json',
		contentType: "application/json",
		async: false, 
        url: ctx + '/au.do?action=10&pageIndex=' + (pageIndex + 1) + '&pageSize=' + pageSize,      //提交到一般处理程序请求数据  
        success: function(data) {
			$.each(data, function(index, value){
				$("#tableHeader").after(getInfoForTable(value.userName,value.sex,value.email,value.phoneNum,value.lastVisit,value.registeTime,value.id));
			});
        }  
    });              
}

function applyIng(){
	window.location.href="sellers.jsp";
}
function headTable(){
	var string = "";
	string+="<tr id=\"tableHeader\">";
	string+="<td style=\"color: #999;\">商家名</td>";
	string+="<td style=\"color: #999;\">商家性别</td>";
	string+="<td style=\"color: #999;\">商家邮箱</td>";
	string+="<td style=\"color: #999;\">商家电话</td>";
	string+="<td style=\"color: #999;\">最后访问时间</td>";
	string+="<td style=\"color: #999;\">商家期限</td>";
	string+="<td style=\"color: #999;\">操作</td>";
	string+="</tr>";
	
	$("#tableData").html(string);
}
function getInfoForTable(userName,sex,email,phoneNum,lastVisit,registeTime,id){
	var str = "<tr>";
		str += "<td style=\"color:red;\">"+userName+"</td>";
		if(sex == "0"){
			sex = "男";
		}else{
			sex = "女";
		}
		str += "<td>"+sex+"</td>";
		str += "<td style=\"color:red;\">"+email+"</td>";
		str += "<td style=\"color:red;\">"+phoneNum+"</td>";
		str += "<td><span style=\"color:green;\">"+lastVisit+"</span>A</td>";
		str += "<td>"+registeTime+"</td>";
		str += "<td><a style=\"cursor:pointer;\" onclick=\"details('"+id+"')\"><img src=\"../image/detail.png\"/></a>" +
				"<a style=\"cursor:pointer;\" onclick=\"deletes('"+id+"')\"><img src=\"../image/delete.jpg\"/></a>" +
						"<a style=\"cursor:pointer;\" onclick=\"audits('"+email+"')\"><img src=\"../image/shenhe.jpg\"/></a></td>";
		str += "</tr>";
		
	return str;
}

function details(id){
	window.open(ctx + "/che.do?id="+id+"&action=1", "_blank");
}

function audits(email){
	$.ajax({
    	type : 'get',
		dataType: 'text',
		contentType: "application/json", 
        url: ctx + '/au.do?action=11&email=' + email,      //提交到一般处理程序请求数据  
        success: function(data) {
        	if(data == "1"){
				layer.alert("审核成功", 1);
				window.location.href = "sellers.jsp";
        	}else{
        		layer.alert("审核失败", 1);
        	}
        }  
    });
}
function deletes(id){
	if(confirm("确定删除信息？")){
		$.ajax({
	    	type : 'get',
			dataType: 'text',
			contentType: "application/json", 
	        url: ctx + '/che.do?action=6&id=' + id,      //提交到一般处理程序请求数据  
	        success: function(data) {
	        	if(data == "1"){
	        		location.reload();
					layer.alert("删除成功", 1);
	        	}else{
	        		layer.alert("删除失败", 1);
	        	}
	        }  
	    });
	}
}

function dateFormat(date){
	var formatDate = "";
	var month = date.split(' ')[0];
	var day = date.split(' ')[1];
	var year = date.split(' ')[2].replace(",","");
	switch(month){
		case "一月":
			month = "01";
			break;
		case "二月":
			month = "02";
			break;
		case "三月":
			month = "03";
			break;
		case "四月":
			month = "04";
			break;
		case "五月":
			month = "05";
			break;
		case "六月":
			month = "06";
			break;
		case "七月":
			month = "07";
			break;
		case "八月":
			month = "08";
			break;
		case "九月":
			month = "09";
			break;
		case "十月":
			month = "10";
			break;
		case "十一月":
			month = "11";
			break;
		case "十二月":
			month = "12";
			break;
	}
	
	day=day.replace(/,/ig,""); 
	if(day.length == 1){
		day = "0" + day;
	}
	
	formatDate = year + "-" + month + "-" + day;
	return formatDate;
}
